﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Reflection;

namespace QL_Truong_Hoc.Tools.CatAnh
{
    public partial class frmCatAnh : DevExpress.XtraEditors.XtraForm
    {
        public bool ImageSelected { get; set; }
        public Bitmap ImageHS { get; set; }

        clsUserRect mobjRect;

        public frmCatAnh(string strImagePath)
        {
            InitializeComponent();

            ImageSelected = false;

            if (!System.IO.File.Exists(strImagePath))
            {
                clsCommon.fncMsgError("File không tồn tại.");
                return;
            }

            picAnh.Image = Image.FromFile(strImagePath);

            mobjRect = new clsUserRect(new Rectangle(10, 10, 100, 100));
            mobjRect.SetPictureBox(this.picAnh);
        }

        private void frmCatAnh_Load(object sender, EventArgs e)
        {

        }
        
        private void mniSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                // Create a Bitmap object from a file.
                Bitmap myBitmap = new Bitmap(picAnh.Image);

                // Clone a portion of the Bitmap object.
                Rectangle cloneRect = mobjRect.rect;
                System.Drawing.Imaging.PixelFormat format = myBitmap.PixelFormat;
                this.ImageHS = myBitmap.Clone(cloneRect, format);

                ImageSelected = true;
                this.Close();
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void mniCancel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ImageSelected = false;
            this.Close();
        }
    }
}